from selenium import webdriver
from selenium.webdriver import ActionChains
import time

# 建立浏览器对象
browser = webdriver.Chrome('D:\AI\Git\gitfiles\django-test\chromedriver.exe')

# 打开网址
browser.get('http://localhost:8080/login_zk')

# 群体选择器（模糊匹配）
browser.find_element_by_xpath('/html/body/div/div/form/div[1]/div/div/input').send_keys('lala')
browser.find_element_by_xpath('/html/body/div/div/form/div[2]/div/div/input').send_keys('123456')
time.sleep(2)

# 定义拖动对象
button = browser.find_element_by_class_name('dv_handler')
box = browser.find_element_by_class_name('dv_text')

# 获取按钮长度
square_len = button.size.get('width')
# 获取滚动条长度
box_len = box.size.get('width')

# print(square_len,box_len)
# 定义拖动对象
action = ActionChains(browser)
# 定义拖动类型
action.click_and_hold(button).perform()
# 拖动距离
action.move_by_offset((box_len-square_len),0).perform()
# 释放动作
action.reset_actions()

time.sleep(1)
browser.find_element_by_class_name('el-button').click()

time.sleep(3)
browser.close()